﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <script src="~/layui/lay/jquery-3.4.1.min.js"></script>
    <script src="~/layui/lay/JSBarcode.all.min.js"></script>
    <meta name="viewport" content="width=device-width" />
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    <link href="~/layuimini/css/public.css" rel="stylesheet" />
    <style>
        td .layui-table-cell {
            width: 100px;
        }
    </style>
    <title>销售单据明细表</title>
</head>
<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <fieldset class="table-search-fieldset">
                <legend>往来单位搜索</legend>
                <div style="margin: 10px 10px 10px 10px" display:none;>
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="name" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>
            <table class="layui-hide" id="test" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    @*<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                        <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
                        <button class="layui-btn layui-btn-warm  layui-btn-sm data-count-edit" lay-event="edit"> 修改 </button>*@
                </div>
            </script>
        </div>
    </div>
</body>
</html>
<script src="~/layui/layui.js"></script>
<script>

    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#test',
            method:'post',
            url: '@Url.Action("DlySaleList", "Home")',
            request: {
                pageName: 'PageIndex' //页码的参数名称，默认：page
              , limitName: 'PageSize' //每页数据量的参数名，默认：limit
            },
            where: {
                Search: $('#Name').val()

            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print'],
            cols: [[
                { type: "checkbox", width: 100 },
                { field: 'Vchcode', title: 'ID', width: 100 },
                { field: 'BtypeName', title: '往来单位', width: 100 },
                { field: 'EmployeeName', title: '职员', width: 100 },
                { field: 'StockName', title: '仓库', width: 100 },
                { field: 'ptypeName', title: '存货', width: 100 },
                { field: 'Qty', title: '数量', width: 100 },
                { field: 'discount', title: '折扣', width: 100 },
                { field: 'DiscountPrice', title: '折后单价', width: 100 },
                { field: 'costtotal', title: '成本金额', width: 100 },
                { field: 'costprice', title: '成本单价', width: 100 },
                { field: 'Blockno', title: '批号', width: 100 },
                { field: 'price', title: '单价', width: 100 },
                { field: 'total', title: '金额', width: 100 },
                { field: 'Prodate', title: '到期日期', width: 100 },
                { field: 'TaxPrice', title: '含税单价', width: 100 },
                { field: 'TaxTotal', title: '税额', width: 100 },
                { field: 'comment', title: '行摘要', width: 100 },
                { field: 'date', title: '单据日期', width: 100 },
                { field: 'usedtype', title: '明细类型', width: 100 },
                { field: 'period', title: '会计期间', width: 100 },
                { field: 'tax_total	', title: '价税合计', width: 100 },
                { field: 'tax', title: '税率', width: 100 },
                { field: 'discounttotal', title: '折后金额', width: 100 },
                { field: 'T_GBL_VchtypeName', title: '单据类型 ', width: 100 },
                { field: 'redword', title: '是否红字单据', width: 100 },
                { field: 'dlyorder', title: '自增长字段', width: 100 },
                { field: 'unit', title: '单位', width: 100 },
                { field: 'PDETAIL', title: '明细库存标识 ', width: 100 },
                { field: 'SourceDlyOrder', title: '上游单据明细', width: 100 },
                { field: 'Toqty', title: '累计退货数量', width: 100 },
                { field: 'workshopName', title: '车间', width: 100 },
                { field: 'RedOld', title: '是否红冲', width: 100 },
                { field: 'UserDefined01', title: '存货1', width: 100 },
                { field: 'UserDefined02', title: '存货2', width: 100 },
                { field: 'QtyOther', title: '副单位数量', width: 100 },
                { field: 'SourceVchcode', title: '上游单据', width: 100 },
                { field: 'SourceVchtype', title: '上游单据类型', width: 100 },
                { field: 'RowNo', title: '行号', width: 100 },
                { field: 'DeparmentName', title: '部门', width: 100 },
                { field: 'Appoint', title: '是否参与成本计算', width: 100 },
                { field: 'Draft', title: '单据状态', width: 100 },
                { field: 'FreeDomDateDif', title: '日期间隔', width: 100 },
                { field: 'BtypeName', title: '结算单位', width: 100 },
                { field: 'BtypeOtherCode', title: '对方编码', width: 100 },
                { field: 'DetailSign', title: '赠品标识', width: 100 },
                { field: 'ProduceDate', title: '生产日期', width: 100 }, 
                { field: 'PriceTraceSign', title: '价格跟踪标识', width: 100 },
                { field: 'MtypeName', title: '项目', width: 100 },
                //{ title: "操作", templet: '#barDemo', align: 'center', width: 120 },

            ]],
            limits: [10, 20, 30, 50, 100],
            limit: 20,
            page: true,
            //skin: 'line',
            totalRow: false,
            height: 'full-170',
            //size:'sm',
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('test', {
                 where: {
                     Search: $('#name').val()
                }
            }, 'data');
            return false;
        });
        //-----------------------------------------------------------
        table.on('toolbar(test)', function (obj) {
            //var Phone = obj.field;
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "/Home/Add?ID=0",
                    end: function () { //最后执行reload
                        location.reload();
                    }
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus(obj.config.id)
   , data = checkStatus.data; //获取选中的数据
                //var ID = data[0].ID;
                console.log(data[0].ID);
                //layer.confirm('删除ID为' + data[0].ID + "的用户吗?",{btn: ['确定', '取消'],title:"提示"}, function (index) {
                    $.ajax({
                        url: '@Url.Action("DeleteUsersAsync", "Home")',
                        type: 'post',
                        data: { 'ID': data[0].ID },
                        success: function (data) {
                            layer.msg("删除成功", {
                                icon: 1, end: function () { //最后执行reload
                                    location.reload();
                                }
                            });
                        }
                    });
                //table.reload('test', {
                //}, 'data');
            } else if (obj.event === 'edit') {  // 监听修改操作
                var checkStatus = table.checkStatus(obj.config.id)
   , data = checkStatus.data; //获取选中的数据
                var ID = data[0].ID;
                console.log(ID)
                //layer.confirm('删除ID为' + data[0].ID + "的用户吗?",{btn: ['确定', '取消'],title:"提示"}, function (index) {
                var index = layer.open({
                    title: '修改用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "/Home/edit?ID="+ID,
                    end: function () { //最后执行reload
                        location.reload();
                    }
                });
                table.reload('test', {
                }, 'data');
            }
        });
    });
        function RefreshTable() {
            table.reload('table', {
                where: {
                    Search: $('#name').val()
                }
            }, 'data');
        }
        function BtnSale(date) {
            var SaleID = data.id;
            var btns = "";
            btns += "<button type='button' class=layui-btn layui-btn-normal layui-btn-sm data-add-btn' onclick=openDetailed(" + SaleID + ")>anniu1</button>"
            return btns;
        }
        function openDetailed(SaleID) {
            window.location.href = "/Home/Index?SaleID=" + SaleID;
        }
</script>
